package com.ityy.ruiji.service.impl;

import com.ityy.ruiji.common.R;
import com.ityy.ruiji.dao.UserDao;
import com.ityy.ruiji.entity.User;
import com.ityy.ruiji.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.events.Event;

@Service
public class UserServiceImpl implements UserService {

    @Autowired(required = false)
    private UserDao userDao;
    @Override
    public R login(String phone, String code, String attribute) {
        if (code.equals(attribute)) {
            User userPhone = userDao.findByPhone(phone);
            if (userPhone!=null){
                return R.success(userPhone);
            }else {
                userPhone = new User();
                userPhone.setPhone(phone);
                userPhone.setStatus(1);
                userDao.insert(userPhone);
                return R.success(userPhone);
            }
        }else {
            return R.error("验证码错误");
        }
    }
}
